<template>
  <div id="app">
    <div id="table">
      <el-table
        :data="tableData"
        stripe
        style="width: 100%"
        class="table"
        height="650"
        max-height="650"
        highlight-current-row
        v-loading="loading"
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.8)"
        id="out_table"
      >
        <el-table-column prop="datetime" label="日期" width="140">
        </el-table-column>
        <el-table-column prop="time" label="时间" width="140">
        </el-table-column>
        <el-table-column prop="week" label="星期" width="140">
        </el-table-column>
        <el-table-column prop="isweekend" label="是否周末" width="140">
        </el-table-column>
        <el-table-column prop="weather" label="天气" width="140">
        </el-table-column>
        <el-table-column prop="traffic_volunm" label="交通流" width="140">
        </el-table-column>
        <el-table-column prop="population_heat" label="人流"> </el-table-column>
        <el-table-column prop="current_parking_no" label="实际停车位">
        </el-table-column>
        <el-table-column prop="prediction" label="预测"> </el-table-column>
      </el-table>
    </div>

    <div id="btn" @click="change()">
      <el-tooltip content="点击显示图" placement="top">
        <el-button icon="el-icon-sort" type="info" circle></el-button>
      </el-tooltip>
    </div>
    <el-drawer
      size="85%"
      :visible.sync="drawer"
      :direction="direction"
      :before-close="handleClose"
    >
      <div class="line" ref="echart2"></div>
    </el-drawer>
  </div>
</template>

<script>
import axios from "axios";
import * as echarts from "echarts";

export default {
  data() {
    return {
      //   表格数据
      tableData: [],
      loading: true,
      drawer: false,
      direction: "ttb",
      dataLine: {},
    };
  },
  methods: {
    filterTag(value, row) {
      return row.status === value;
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
    setEcharts() {
      this.$nextTick(() => {
        var myChart = echarts.init(this.$refs.echart2);
        //组件大小随窗口自适应
        window.addEventListener("resize", function () {
          myChart.resize();
        });
        var option = {
          title: {
            text: "预测与实际比较",
            left: "center",
          },
          xAxis: {
            type: "category",
            boundaryGap: false,
            data: this.dataLine.x,
          },
          yAxis: {
            type: "value",
          },
          legend: {
            data: ["true", "pre"],
            left: 80,
          },
          series: [
            {
              name: "true",
              data: this.dataLine.true,
              type: "line",
            },
            {
              name: "pre",
              data: this.dataLine.pre,
              type: "line",
            },
          ],
        };
        myChart.setOption(option);
      });
    },
    change(){
      this.drawer = true;
      this.$nextTick(()=>{
        this.setEcharts();
      })
    },
  },
  async created() {
    const res = await axios({
      method: "GET",
      url: "static/pre.json",
    });
    //   console.log(res.data);
    this.tableData = res.data;
    this.loading = false;

    const dataX = await axios({
      method: "GET",
      url: "static/line.json",
    });
    this.dataLine = dataX.data;

  },

  updated() {
    // this.setEcharts();
  },
};
</script>

<style scoped>
.table {
  margin-top: 10px;
}
#app {
  position: relative;
}

#btn {
  position: absolute;
  bottom: 30px;
  right: 80px;
}

.el-row {
  margin-left: 10px;
  margin-top: 20px;
  margin-bottom: 20px;
}
.el-row:last-child {
  margin-bottom: 0;
}
.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #99a9bf;
}
.bg-purple {
  /* background: #d3dce6; */
}
.bg-purple-light {
  background: #e5e9f2;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.row-bg {
  padding: 10px 0;
  background-color: #f9fafc;
}
.addbtn {
  margin-top: 12px;
  margin-left: 15px;
}
.line {
  margin: 0px auto;
  width: 1000px;
  height: 532px;
}
</style>
